home *** CD-ROM | disk | FTP | other *** search
- Path: news.acay.com.au!news
- From: nsouto@acay.com.au
- Newsgroups: comp.lang.c
- Subject: Re: quick decision: is n a power of 2?
- Date: 27 Jan 1996 03:06:42 GMT
- Organization: ACAY Network Computing P/L, Sydney AUSTRALIA.
- Message-ID: <4ec4s2$sfs@www.acay.com.au>
- References: <Pine.OSF.3.91.960119114608.18779E-100000@io.UWinnipeg.ca>
- Reply-To: nsouto@acay.com.au
- NNTP-Posting-Host: nsouto.acay.com.au
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <Pine.OSF.3.91.960119114608.18779E-100000@io.UWinnipeg.ca>, Bill Simpson <wsimpson@uwinnipeg.ca> writes:
- >Is there a fast way to decide whether a number n is a power of 2?
- >Bill Simpson
-
-
- PMFJI. I may be PITW, but I think the easiest way would be to look at a power of
- 2 as a binary number: it's gotta be a 1 followed by zero or more 0's. Ie:
-
- 1
- 10
- 100
- 1000
- etc.
-
- That should be a nice and fast way of looking for a 2*n number? ;-)
-
- HTH
-
-
-